package com.zznzzn.myweb.util;


import com.zznzzn.myweb.Properties.MyProperties;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

import java.io.*;
import java.net.URL;

@Component
@Data
public class RsaKeys {

    @Autowired
    private MyProperties properties;

    private String pubKey = "";
    private String privkey = "";

    public void loadKeys() {


        try {

            File file1 = ResourceUtils.getFile(properties.getPriv_key_location());
            File file2 = ResourceUtils.getFile(properties.getPub_key_location());
//            URL url2 = getClass().getClassLoader().getResource(properties.getPub_key_location());

            BufferedReader privreader = new BufferedReader(new FileReader(file1));
            BufferedReader pubreader = new BufferedReader(new FileReader(file2));

            String tmp;
            while ((tmp = pubreader.readLine()) != null) {
                this.pubKey = this.pubKey + tmp;
            }
            while ((tmp = privreader.readLine()) != null) {
                this.privkey = this.privkey + tmp;
            }
            privreader.close();
            pubreader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




}
